package com.common.data.desensitization.common.handler;

import com.common.data.desensitization.common.annotation.DesensitizationRule;
import com.common.data.desensitization.common.utils.RepeatMaskUtil;
import org.springframework.stereotype.Component;

@Component
public class DesensitizeSuffixKeepHandler implements DesensitizationHandler{
    @Override
    public String desensitize(String originalValue, DesensitizationRule rule) {
        if (rule.suffixKeep() <= 0) return RepeatMaskUtil.repeatMask(originalValue.length(), rule.maskChar());
        if (originalValue.length() <= rule.suffixKeep()) return originalValue;
        return RepeatMaskUtil.repeatMask(originalValue.length() - rule.suffixKeep(), rule.maskChar()) + originalValue.substring(originalValue.length() - rule.suffixKeep());
    }
}
